#include "Host.h"
#include "NodeServer.h"
#include "Game.h"

CHostBase* CreateHost()
{
	CHost* pHost = new CHost();
	return pHost;
}

std::string GetLogFileName()
{
	return "agencyeventcb";
}

CHost::CHost()
{
}

CHost::~CHost()
{
}


void CHost::Init()
{
	this->m_pNode = GetNodeServer();
	this->m_pGame = new CGameServer();
	this->m_pGame->m_pHost = this;
	this->m_pGame->InitGame();

	SpiderEvent ev;
	ev.evID = NODE_EV_SET_TYPE;
	ev.evParam.iParam = SERVER_TYPE_AGENCY_EVENT_CALLBACK;
	m_pNode->ProcEvent(NODE_EV_SET_TYPE, &ev);
}


int CHost::OnBYTimeOut(int Timerid)
{
	return 0;
}

int CHost::ProcEvent(int ev_id, SpiderEvent* pEvent)
{
	if (HOST_EV_GAME_INIT == ev_id)
	{
		// 初始化支持多线程发送
		this->InitMtSend();
	}
	else if (HOST_EV_BACK_CONNECTED == ev_id)
	{		
		if (NULL != m_pGame)
		{
			return m_pGame->ProcEventBackConn(ev_id, pEvent);
		}
	}
	return 0;
}


int CHost::ProcPacket(NETInputPacket* inputPkg, SocketHandler* pSocketHandler)
{
	if (NULL != m_pGame)
	{
		return m_pGame->ProcessPacket(pSocketHandler, inputPkg);
	}
	return 0;
}